<template>
  <!-- 添加产品 -->
  <div class="add-person-detail">
    <a-modal title="编辑个人信息" :visible="props.show" @ok="handleOK" @cancel="close">
      <a-form :label-col="{span:6}" :wrapper-col="{span:12}">
        <a-form-item label="用户账号">
          <a-input v-model:value="formData.account" placeholder="不可编辑" />
        </a-form-item>
        <a-form-item label="用户姓名">
          <a-input v-model:value="formData.realName" />
        </a-form-item>
        <a-form-item label="性别">
          <!-- <a-input v-model:value="formData.sex" />  style="width: 100%"-->
          <a-select v-model:value="formData.sex">
            <a-select-option value="0">男</a-select-option>
            <a-select-option value="1">女</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="生日">
          <a-date-picker v-model:value="formData.birthday" />
        </a-form-item>
        <a-form-item label="手机号">
          <a-input v-model:value="formData.phoneNumber" />
        </a-form-item>
        <a-form-item label="籍贯">
          <a-input v-model:value="formData.home" />
        </a-form-item>
        <a-form-item label="婚姻状况">
          <a-select v-model:value="formData.marriage">
            <a-select-option value="0">未婚</a-select-option>
            <a-select-option value="1">已婚</a-select-option>
            <a-select-option value="2">离异</a-select-option>
          </a-select>
          <!-- <a-input v-model:value="formData.marriage" /> -->
        </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>

<script>
import { defineComponent, reactive } from "vue";
import { personalDetail } from "../../../service";
import { result, deepClone } from "../../../utils/result";
import { timeTransfer } from "../../../utils/timeTransfer";
import store from "../../../store/index";
export default defineComponent({
  props: {
    show: {
      type: Boolean,
      default: false,
    },
   
  },
  setup(props, context) {
    //展示表单默认数据
    const formData = reactive({
      account: store.state.userInfo.username,
      realName: "",
      sex: "",
      birthday: "",
      phoneNumber: "",
      home: "",
      marriage: "",
    });
    // console.log('props.initData',props.initData);
    // const formData = JSON.parse(JSON.stringify(props.initData));
    //发送请求表单数据
    const handleOK = async () => {
      const formReq = deepClone(formData);
      formReq.account = store.state.userInfo._id;
      formReq.birthday = timeTransfer(formReq.birthday);
      // console.log("打印formReq", formReq);
      const res = await personalDetail.add(formReq);
      if (res.data.code == 200) {
        console.log("打印personalDetail_res", res);
      }
      result(res)
        .success((res) => {
          console.log("打印personalDetail_res", res);
        })
        .fail(() => {});

      context.emit("setShow", false);
    };

    const close = () => {
      context.emit("setShow", false);
    };
    return {
      formData,
      handleOK,

      props,
      close,
    };
  },
});
</script>

<style lang='less'>
</style>